if (!window.loading_html) window.loading_html = '<div style="margin:20px;">Loading...</div>';

function $_(obj)
{
	return document.getElementById(obj);
}

function getOuterHTML(obj)
{
	var div = document.createElement('div');
	div.appendChild(obj.cloneNode(1));
	return div.innerHTML;
}

function load_admin()
{
	load('view/js/admin.js.css');
	load('js.php?p=admin');
}



function load(url,css)
{
	var ext = url.substring(url.length-4,url.length);
	var head = document.getElementsByTagName('head');
	head = head[0];
	if (ext.toLowerCase() == '.css' || css)
	{
		var dom = document.createElement('link');
		dom.rel = "stylesheet";
		dom.href = url;
	}
	else 
	{
		var dom = document.createElement('script');
		dom.src = url;
	}
	head.appendChild(dom);
}

function get_value_from_url(url,key)
{
	eval('var re = /'+key+'=([^&]*)/;');
	re = re.exec(url);
	if (re) return re[1];
}


window.refresh = function()
{
	window.location.reload();
}


function get_page_size()
{
	var re = {};
	if (document.documentElement && document.documentElement.clientHeight)
	{
		var doc = document.documentElement;
		re.width = (doc.clientWidth>doc.scrollWidth)?doc.clientWidth:doc.scrollWidth;
		re.height = (doc.clientHeight>doc.scrollHeight)?doc.clientHeight:doc.scrollHeight;
	}
	else
	{
		var doc = document.body;
		re.width = (window.innerWidth>doc.scrollWidth)?window.innerWidth:doc.scrollWidth;
		re.height = (window.innerHeight>doc.scrollHeight)?window.innerHeight:doc.scrollHeight;
	}
	return re;
}


function popup(data)
{
	var bg = document.createElement('div');
	var page = get_page_size();
	$(bg).css(
		{
			height: page.height,
			width: page.width,
			zIndex: '999',
			position:'absolute',
			top:'0px',
			left:'0px',
			padding:'0px',
			backgroundColor:'transparent',
			margin:'0px',
			opacity:0
		});
	$(bg)
		.attr('id','popup_bg')
		.attr('popup','yes')
		.bind('click',close_popup)
		.css('background-color','#000000')
		.fadeTo(300,0.4);
		
	
	$(document.body).append(bg);
	data.top = $(document).scrollTop() + ($(window).height() - data.height ) / 2 - 40;
	data.left = $(document).scrollLeft() + ($(window).width() - data.width ) / 2;
	
	var div = document.createElement('div');
	$(div)
		.css(
		{
			height: data.height,
			width: data.width,
			zIndex: '1000',
			backgroundColor: '#fff',
			position:'absolute',
			padding:'0px',
			margin:'0px',
			opacity:0.98,
			border:'2px solid lightblue',
			overflow:'auto'
		})
		.css('top',data.top)
		.css('left',data.left)
		.attr('popup','yes');
	var divbg = div.cloneNode(1);
	divbg.id='popup_img_divbg';
	divbg.style.zIndex = 999;
	$(div)
		.attr('id','popup_img_div')
		.attr('source_src',data.url)
		.css('background','#ffffff url(images/loading.gif) no-repeat 50% 50%')
		//.html(window.loading_html)
		.fadeIn();
		//.bind('click',function(event){ event.returnValue = false; return false; });
		
	$(document.body).append(div);
	$(document.body).append(divbg);

	$.post(data.url,{ },function(s)
	{
		$('#popup_img_div').fadeOut(100,function()
		{
			/*
			var _div = document.createElement('div');
			$(_div).css( 
			{ 
				alpha:0.5
			});
			$(divbg).append(_div);
			
			
			alert(_div.offsetHeight);
			*/
			
			$(this).css('background','#ffffff url() no-repeat -1000px 0px').html(s).fadeIn(100,function()
			{
				var span = document.createElement('span');
				span.innerHTML = s;
				var arr = span.getElementsByTagName('script');
				var head = document.getElementsByTagName('head')[0];
				for(var i=0;i<arr.length;i++)
				{
					var dom = arr[i].cloneNode(1);
					head.appendChild(dom);
				}
				span = null;
			})
		});
		
	});
}

function close_popup()
{
	$('[popup]').fadeOut('fast',function()
	{
		$('[popup]').each(function()
		{
			this.parentNode.removeChild(this);
		});
	});
}
